package com.gaofeng.day21;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class demo01 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();

        Collections.addAll(list,"张无忌-男-15","张无忌1-男-15","周芷若-女-20","小昭-女-18","张三丰-男-100","谢逊-男-40");
        List<String> collect = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toList());
        System.out.println(collect);

        Set<String> collect1 = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toSet());
        System.out.println(collect1);
        boolean contains = collect1.contains("张无忌-男-15");
        System.out.println(contains);
        Map<String, Integer> collect2 = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split("-")[0];
            }
        }, new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s.split("-")[2]);
            }
        }));
        System.out.println(collect2);

        Map<String, Integer> collect3 = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toMap(
                s -> s.split("-")[0],
                s -> Integer.parseInt(s.split("-")[2])
        ));
        System.out.println(collect3);
    }
}
